package com.cmc.cloud.cmclink.doc.api.document.req.so.sovo.socargovo;

import com.cmc.cloud.cmclink.doc.api.document.emums.CargoTypeEnum;
import com.cmc.cloud.cmclink.doc.api.document.emums.SubCargoTypeEnum;
import com.cmc.cloud.cmclink.doc.util.so.CompareUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * 订舱货物信息 Base VO，提供给添加、修改、详细的子 VO 使用
 * 如果子 VO 存在差异的字段，请不要添加到这里，影响 Swagger 文档生成
 *
 * @author codegen
 */
@Data
public class SoCargoBaseVO {

    @Schema(description = "外键", requiredMode = Schema.RequiredMode.REQUIRED, example = "29832")
    private Long soId;

    @Schema(description = "货类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotBlank(message = "{socargo.cargotype.notblank}")
    @Length(max = 5, message = "{socargo.cargotype.length}")
    private String cargoType;

    @Schema(description = "HS Code", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "{socargo.hscode.notblank}")
    @Length(max = 12, message = "{socargo.hscode.length}")
    private String hsCode;

    @Schema(description = "英文品名")
    @Length(max = 4000, message = "{socargo.commodityen.length}")
    private String commodityEn;

    @Schema(description = "中文品名")
    @Length(max = 1000, message = "{socargo.commoditycn.length}")
    private String commodityCn;

    @Schema(description = "货类子类 如果货类是DRY ，这里就需要再选择子类 是不是液袋货FLEXI、半开门ODO，如果都不是则为空", example = "1")
    @Length(max = 10, message = "{socargo.subcargotype.length}")
    private String subCargoType;

    @Schema(description = "预估毛重（kgs）", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "{socargo.grossweight.notnull}")
    private BigDecimal grossWeight;

    @Schema(description = "温度（℃） 温度范围在-25℃至25℃ 之间。")
    @Length(max = 4, message = "{socargo.temperature.length}")
    private String temperature;

    @Schema(description = "通风度 开度（% Open，范围0~100%）；风量（CHM，单位：m³/h，范围0~999）")
    @Length(max = 50, message = "{socargo.vantilation.length}")
    private String vantilation;

    @Schema(description = "C 摄氏度,F华氏")
    @Length(max = 1, message = "{socargo.temperatureunit.length}")
    private String temperatureUnit;

    @Schema(description = "unno")
    @Length(max = 50, message = "{socargo.unno.length}")
    private String unNo;

    @Schema(description = "imoclass")
    @Length(max = 50, message = "{socargo.imoclass.length}")
    private String imoClass;

    @Schema(description = "闪点特种货带过来的")
    @Length(max = 50, message = "{socargo.flashpoint.length}")
    private String flashPoint;

    @Schema(description = "包装组别三个选项：Ⅰ、Ⅱ、Ⅲ")
    @Length(max = 5, message = "{socargo.packinggroup.length}")
    private String packingGroup;

    @Schema(description = "唛头")
    @Length(max = 4000, message = "{socargo.marks.length}")
    private String marks;

    @Schema(description = "件数")
    private Integer quantity;

    @Schema(description = "尺寸")
    private BigDecimal measurement;

    @Schema(description = "包装代码")
    @Length(max = 50, message = "{socargo.packagecode.length}")
    private String packageCode;

    @Schema(description = "包装描述")
    @Length(max = 50, message = "{socargo.packagedesc.length}")
    private String packageDesc;

    public static CompareUtils<SoCargoBaseVO> getMultiFieldComparator() {
        return new CompareUtils<SoCargoBaseVO>().comparingField(SoCargoBaseVO::getCargoType)
                .thenComparing(SoCargoBaseVO::getHsCode)
                .thenComparing(SoCargoBaseVO::getCommodityEn)
                .thenComparing(SoCargoBaseVO::getCommodityCn)
                .thenComparing(SoCargoBaseVO::getGrossWeight);
    }

    public static CompareUtils<SoCargoBaseVO> getMultiFieldComparatorMain() {
        return new CompareUtils<SoCargoBaseVO>().comparingField(SoCargoBaseVO::getCargoType)
                .thenComparing(SoCargoBaseVO::getHsCode);
    }

    public static boolean checkSpecialCargo(SoCargoBaseVO soCargoDO) {
        return checkSpecialCargo(soCargoDO.getCargoType(), soCargoDO.getSubCargoType());
    }

    public static boolean checkSpecialCargo(String cargoType, String subCargoType) {
        if (CargoTypeEnum.AK.getValue().equals(cargoType) || CargoTypeEnum.RD.getValue().equals(cargoType) || CargoTypeEnum.DG.getValue().equals(cargoType)) {
            return true;
        }

        return CargoTypeEnum.DRY.getValue().equals(cargoType) && (SubCargoTypeEnum.FLEXI.getValue().equals(subCargoType)
                || SubCargoTypeEnum.ODO.getValue().equals(subCargoType));
    }

}
